package com.memoir.common;

import com.memoir.enums.ResponseConstantEnums;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.stereotype.Service;

import java.io.Serializable;
public class ServerResponse implements Serializable {
    @Schema(description = "code")
    private String code;
    @Schema(description = "描述")
    private String msg;
    @Schema(description = "数据")
    private Object data;
    public ServerResponse() {}

    public static ServerResponse buildSuccess(ResponseConstantEnums enums){
        return buildObejct(enums);
    }


    public static ServerResponse buildSuccess(ResponseConstantEnums enums,Object data){
        ServerResponse response = buildObejct(enums);
        response.setData(data);
        return response;
    }


    public static ServerResponse buildError(ResponseConstantEnums enums){
        return buildObejct(enums);
    }

    private static ServerResponse buildObejct(ResponseConstantEnums enums){
        ServerResponse response = new ServerResponse();
        response.setCode(enums.getCode());
        response.setMsg(enums.getMsg());
        return response;
    }

    public static ServerResponse buildSuccess(Object data){
        ServerResponse response = buildObejct(ResponseConstantEnums.SUCCESS);
        response.setData(data);
        return response;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
